home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / basic / ShapesFix.lha / ShapesFix / ShapesFix.asc next >
Encoding:
Text File  |  2000-09-17  |  4.2 KB  |  147 lines

  1.  
  2. ; $VER: ShapesFix.bb2 v1.1 (17.09.2000)
  3.  
  4. ; Author: Damir Arh
  5. ; Thanks go to: David McMinn
  6. ; E-mail: damir.arh@telesat.si
  7. ; WWW:    http://damir.gajba.net/
  8.  
  9. ; This source code is completely free. You can redistribute
  10. ; and/or modify it without any restrictions whatsoever.
  11.  
  12. ;-------------------------------------------------------------
  13.  
  14. ; These two functions are meant as a replacement for the buggy
  15. ; commands CopyShape and Scale which trash the image when its
  16. ; size exceeds 32 KB. You can use these functions safely as
  17. ; long as the size of the single bitplane doesn't exceed 32 KB.
  18. ; In case it does you'll probably have to rewrite the blit
  19. ; functions, too.
  20.  
  21. ; At the end of this source ('main' label) there's a small
  22. ; demo to show you how to use the functions. You can also
  23. ; easily check that the functions now work fine by compiling
  24. ; this program and loading a suitable image.
  25.  
  26.  
  27. ;-------------------------------------------------------------
  28. .FixedScale:
  29. ;-------------------------------------------------------------
  30.  
  31. ; This function is meant as a replacement for the Scale command.
  32. ; Though it isn't used in exactly the same away. Unlike the Scale
  33. ; command it copies the shape at the same time as it scales it.
  34. ; By doing this the overhead is reduced to minimum as the
  35. ; underlying graphics.library function doesn't support scaling
  36. ; of the overlapping bitmaps. I also thing that such a function
  37. ; is of more use than the original one but if you need the
  38. ; original functionality, you shouldn't have any problems
  39. ; writing a suitable replacement.
  40.  
  41. Statement FixedScaleCopy{source.b,destination.b,dummy.l,x.q,y.q}
  42.  
  43.   ; calculate the scaling factors
  44.   x1.w=100*x
  45.   destwidth.w = ScalerDiv_(ShapeWidth(source),x1,100)
  46.   y1.w=100*y
  47.   destheight.w = ScalerDiv_(ShapeHeight(source),y1,100)
  48.  
  49.   ; setup the destination shape
  50.   *srcshp.shape = Addr Shape(source)
  51.   InitShape destination,destwidth,destheight,*srcshp\_depth
  52.   *destshp.shape = Addr Shape(destination)
  53.  
  54.   ; setup the needed bitmap structures
  55.   DEFTYPE ._BitMap srcbmp, destbmp
  56.   srcbmp\BytesPerRow = *srcshp\_ebwidth
  57.   srcbmp\Rows = *srcshp\_pixheight
  58.   srcbmp\_Depth = *srcshp\_depth
  59.   For i.w=0 To *srcshp\_depth-1
  60.     srcbmp\Planes[i] = *srcshp\_data + i * *srcshp\_ebwidth * *srcshp\_pixheight
  61.   Next i
  62.   destbmp\BytesPerRow = *destshp\_ebwidth
  63.   destbmp\Rows = *destshp\_pixheight
  64.   destbmp\_Depth = *destshp\_depth
  65.   For i.w=0 To *destshp\_depth-1
  66.     destbmp\Planes[i] = *destshp\_data + i * *destshp\_ebwidth * *destshp\_pixheight
  67.   Next i
  68.  
  69.   ; setup the bitmap scale structure
  70.   DEFTYPE .BitScaleArgs bsa
  71.   bsa\bsa_SrcX = 0
  72.   bsa\bsa_SrcY = 0
  73.   bsa\bsa_SrcWidth = ShapeWidth(source)
  74.   bsa\bsa_SrcHeight = ShapeHeight(source)
  75.   bsa\bsa_XSrcFactor = 100
  76.   bsa\bsa_XDestFactor = x1
  77.   bsa\bsa_YSrcFactor = 100
  78.   bsa\bsa_YDestFactor = y1
  79.   bsa\bsa_SrcBitMap = &srcbmp
  80.   bsa\bsa_DestBitMap = &destbmp
  81.   bsa\bsa_Flags = 0
  82.  
  83.   ; preform the actual scaling
  84.   BitMapScale_(&bsa)
  85.   MakeCookie destination
  86.  
  87. End Statement
  88.  
  89.  
  90. ;-------------------------------------------------------------
  91. .FixedCopy:
  92. ;-------------------------------------------------------------
  93.  
  94. ; This function is an exact replacement for the CopyShape
  95. ; command. The functionality and the calling convention
  96. ; is exactly the same.
  97.  
  98. Statement FixedCopyShape{source.b,destination.b}
  99.   *srcshp.shape = Addr Shape(source)
  100.   *dstshp.shape = Addr Shape(destination)
  101.   InitShape destination,*srcshp\_pixwidth,*srcshp\_pixheight,*srcshp\_depth
  102.   CopyMem_ *srcshp\_data, *dstshp\_data, *srcshp\_ebwidth * *srcshp\_pixheight * *dstshp\_depth
  103.   MakeCookie destination
  104. End Statement
  105.  
  106. ;-------------------------------------------------------------
  107. .main:
  108. ;-------------------------------------------------------------
  109.  
  110. ; This is a short demonstration of the above functions. Try it
  111. ; out but there is no need to copy this to your program.
  112.  
  113. Print "Filename: "
  114. filename$=Edit$(256)
  115.  
  116. If Exists(filename$)=0 Then End
  117.  
  118. ILBMInfo filename$
  119. width.l = ILBMWidth
  120. height.l = ILBMHeight
  121. dept.l = ILBMDepth
  122.  
  123. InitShape 0,width,height,dept
  124. ShapesBitMap 0,1
  125. LoadBitMap 1,filename$
  126. LoadPalette 1,filename$
  127. MakeCookie 0
  128.  
  129. Screen 0,0,0,640,512,8,$8004,"",1,1
  130. ScreensBitMap 0,0
  131. Use Palette 1
  132. Cls 0
  133.  
  134. FixedCopyShape{0,1}
  135. ClipBlit 1,0,0
  136.  
  137. MouseWait
  138.  
  139. Cls 0
  140. FixedScaleCopy{0,1,0,0.5,0.5}
  141. ClipBlit 1,0,0
  142.  
  143. MouseWait
  144.  
  145. End
  146.  
  147.